package com.cpi.cornpp.currency.converter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.cpi.cornpp.common.exception.CornPPException;
import com.cpi.cornpp.currency.dto.CurrencyDTO;
import com.cpi.cornpp.currency.exception.CurrencyException;
import com.cpi.cornpp.currency.view.CurrencyView;

public class CurrencyConverter {
	public List convertDTOsTOViews(List currencyDTOs)throws CurrencyException{
		List currencyViews = null;
		Iterator iterator = null;
		CurrencyDTO currencyDTO = null;
		CurrencyView currencyView = null;
		try{
			iterator = currencyDTOs.iterator();
			currencyViews = new ArrayList();
			while(iterator.hasNext()){
				currencyDTO = (CurrencyDTO)iterator.next();
				currencyView = convertDTOTOView(currencyDTO);
				currencyViews.add(currencyView);
			}
		}catch(Exception exception){
			CurrencyException currencyException = null;
			exception.printStackTrace(System.out);
			currencyException = new CurrencyException(exception, CornPPException.LAYER_CONVERTER, CornPPException.ACTION_LISTS);
			throw currencyException;
		}
		return currencyViews;
	}

	private CurrencyView convertDTOTOView(CurrencyDTO currencyDTO) {
		CurrencyView currencyView = null;
		currencyView =  new CurrencyView();
		currencyView.setCurrencyId(currencyDTO.getCurrencyId());
		currencyView.setCode(currencyDTO.getSapCode());
		currencyView.setDesciption(currencyDTO.getDescription());
		return currencyView;
	}
}